home *** CD-ROM | disk | FTP | other *** search
- Path: io.UWinnipeg.ca!wsimpson
- From: Bill Simpson <wsimpson@uwinnipeg.ca>
- Newsgroups: comp.lang.c
- Subject: while loop problem
- Date: Tue, 12 Mar 1996 13:36:41 -0600
- Organization: The University of Manitoba
- Message-ID: <Pine.OSF.3.91.960312133449.7844B-100000@io.UWinnipeg.ca>
- NNTP-Posting-Host: io.uwinnipeg.ca
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=US-ASCII
-
- Consider the following code fragment:
-
- y=2000; z=1000;
- x=0;
- while(x<=XMAX)
- {
- x+=(int) erand(mean);
- setdot(x,y,z);
- }
-
- It plots a line of dots that are randomly (exponentially) spaced, giving
- a 1D spatial Poisson process.
- The problem is that dot x coordinates can only be between 0 and XMAX.
- The above code will also attempt to plot one point at an x value >XMAX
- before it terminates.
-
- Is there a nice way to write the code so it works properly?
-
- The only way I have thought of is
- y=2000; z=1000;
- x=0;
- while(x<=XMAX)
- {
- x+=(int) erand(mean);
- if(x<=XMAX)
- setdot(x,y,z);
- }
-
- which seems very clumsy since the same test is done twice.
-
- Thanks very much for any help.
-
- Bill Simpson
-